package com.hly.tool.library;

import com.hly.tool.constants.Constants;
import com.hly.tool.object.HDomainObject;
import com.hly.tool.string.StringUtil;
import com.matrixone.apps.domain.DomainConstants;
import com.matrixone.apps.domain.DomainObject;
import com.matrixone.apps.domain.util.MapList;
import com.matrixone.apps.library.Libraries;
import matrix.db.Context;
import matrix.db.JPO;
import matrix.util.MatrixException;
import matrix.util.StringList;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/7/14 18:22
 * @description：
 */
public class Library
{


    /**
     * @return
     * @throws Exception
     */
    public static String createLibraryClassObj(Context context, HashMap createMap) throws Exception
    {
        Libraries lib = new Libraries();
        String objectId = lib.createLBCObject(context, createMap);
        return objectId;
    }


    /**
     * 获取创建Library Fields
     *
     * @return
     */
    public static MapList getLibraryFields()
    {

        MapList fields = new MapList();

        Map nameMap = getLibraryNameMap();

        Map titleMap = getLibraryTitleMap();

        Map descriptionMap = getLibraryDescriptionMap();


        fields.add(nameMap);
        fields.add(titleMap);
        fields.add(descriptionMap);
        return fields;
    }

    /**
     * 获取创建Library Fields
     *
     * @return
     */
    public static MapList getLibraryFields(Map nameMap, Map titleMap, Map descriptionMap)
    {

        MapList fields = new MapList();

        fields.add(nameMap);
        fields.add(titleMap);
        fields.add(descriptionMap);
        return fields;
    }


    /**
     * 获取创建Library Fields
     *
     * @return
     */
    public static MapList getLibraryFields(Map nameMap)
    {

        MapList fields = new MapList();

        Map titleMap = getLibraryTitleMap();

        Map descriptionMap = getLibraryDescriptionMap();


        fields.add(nameMap);
        fields.add(titleMap);
        fields.add(descriptionMap);
        return fields;
    }


    /**
     * 获取创建Library Fields 中的nameMap
     *
     * @return
     */
    public static Map getLibraryNameMap()
    {
        //            {field_display_value=[], settings={OnChange Handler=reloadMessageField, Input Type=textbox, Registered Suite=LibraryCentral, Required=true, autoName=自动命名, Validate=validateForBadCharacters, Editable=true, Colspan=0, AutoName Checked=, Field Type=basic, nameMode=autoName}, hasAccess=false, name=Name, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=name, label=名称, StringResourceFileId=emxLibraryCentralStringResource}


        Map nameMap = new HashMap();
        nameMap.put("field_display_value", new MapList());
        nameMap.put("field_value", new MapList());
        Map nameSettings = new HashMap();
        nameSettings.put("OnChange Handler", "reloadMessageField");
        nameSettings.put("Input Type", "textbox");
        nameSettings.put("Registered Suite", "LibraryCentral");
        nameSettings.put("Required", "true");
        nameSettings.put("autoName", "false");
        nameSettings.put("Validate", "validateForBadCharacters");
        nameSettings.put("Editable", "true");
        nameSettings.put("Colspan", "0");
        nameSettings.put("AutoName Checked", "");
        nameSettings.put("Field Type", "basic");
        nameSettings.put("nameMode", "create");
        nameMap.put("settings", nameSettings);
        nameMap.put("hasAccess", "false");
        nameMap.put("name", "Name");
        nameMap.put("suiteDirectory", "documentcentral");
        nameMap.put("suiteKey", "LibraryCentral");
        nameMap.put("label", "\u540d\u79f0");
        nameMap.put("expression_businessobject", "name");
        nameMap.put("StringResourceFileId", "emxLibraryCentralStringResource");
        return nameMap;
    }


    /**
     * 获取创建Library Fields 中的nameMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getLibraryNameMap(Map map)
    {
        //            {field_display_value=[], settings={OnChange Handler=reloadMessageField, Input Type=textbox, Registered Suite=LibraryCentral, Required=true, autoName=自动命名, Validate=validateForBadCharacters, Editable=true, Colspan=0, AutoName Checked=, Field Type=basic, nameMode=autoName}, hasAccess=false, name=Name, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=name, label=名称, StringResourceFileId=emxLibraryCentralStringResource}


        Map nameMap = new HashMap();
        nameMap.put("field_display_value", new MapList());
        nameMap.put("field_value", new MapList());
        Map nameSettings = new HashMap();
        nameSettings.put("OnChange Handler", "reloadMessageField");
        nameSettings.put("Input Type", "textbox");
        nameSettings.put("Registered Suite", "LibraryCentral");
        nameSettings.put("Required", "true");
        nameSettings.put("autoName", "false");
        nameSettings.put("Validate", "validateForBadCharacters");
        nameSettings.put("Editable", "true");
        nameSettings.put("Colspan", "0");
        nameSettings.put("AutoName Checked", "");
        nameSettings.put("Field Type", "basic");
        nameSettings.put("nameMode", "create");
        nameMap.put("settings", nameSettings);
        nameMap.put("hasAccess", "false");
        nameMap.put("name", "Name");
        nameMap.put("suiteDirectory", "documentcentral");
        nameMap.put("suiteKey", "LibraryCentral");
        nameMap.put("label", "\u540d\u79f0");
        nameMap.put("expression_businessobject", "name");
        nameMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        nameMap.putAll(map);
        return nameMap;
    }


    /**
     * 获取创建Library Fields 中的nameMap
     *
     * @return
     */
    public static Map getLibraryTitleMap()
    {
        //            {settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=attribute_Title, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, Field Type=attribute}, DB UnitList=[], hasAccess=true, AssociatedWithUOM=false, label=标题, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], DB Unit=, name=Title, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=attribute[Title].value, isMultiVal=false},

        Map titleMap = new HashMap();
        titleMap.put("field_display_value", new MapList());
        titleMap.put("field_value", new MapList());
        titleMap.put("DB UnitList", new MapList());
        Map titleSettings = new HashMap();
        titleSettings.put("OnChange Handler", "reloadMessageField");
        titleSettings.put("Input Type", "textbox");
        titleSettings.put("Admin Type", "attribute_Title");
        titleSettings.put("Registered Suite", "LibraryCentral");
        titleSettings.put("Required", "true");
        titleSettings.put("Validate", "validateForBadCharacters");
        titleSettings.put("Editable", "true");
        titleSettings.put("Colspan", "0");
        titleSettings.put("Field Type", "attribute");
        titleMap.put("settings", titleSettings);
        titleMap.put("hasAccess", "true");
        titleMap.put("AssociatedWithUOM", "false");
        titleMap.put("name", "Title");
        titleMap.put("DB Unit", "");
        titleMap.put("isMultiVal", "false");
        titleMap.put("suiteDirectory", "documentcentral");
        titleMap.put("suiteKey", "LibraryCentral");
        titleMap.put("label", "\u6807\u9898");
        titleMap.put("expression_businessobject", "attribute[Title].value");
        titleMap.put("StringResourceFileId", "emxLibraryCentralStringResource");
        return titleMap;
    }

    /**
     * 获取创建Library Fields 中的nameMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getLibraryTitleMap(Map map)
    {
        //            {settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=attribute_Title, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, Field Type=attribute}, DB UnitList=[], hasAccess=true, AssociatedWithUOM=false, label=标题, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], DB Unit=, name=Title, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=attribute[Title].value, isMultiVal=false},

        Map titleMap = new HashMap();
        titleMap.put("field_display_value", new MapList());
        titleMap.put("field_value", new MapList());
        titleMap.put("DB UnitList", new MapList());
        Map titleSettings = new HashMap();
        titleSettings.put("OnChange Handler", "reloadMessageField");
        titleSettings.put("Input Type", "textbox");
        titleSettings.put("Admin Type", "attribute_Title");
        titleSettings.put("Registered Suite", "LibraryCentral");
        titleSettings.put("Required", "true");
        titleSettings.put("Validate", "validateForBadCharacters");
        titleSettings.put("Editable", "true");
        titleSettings.put("Colspan", "0");
        titleSettings.put("Field Type", "attribute");
        titleMap.put("settings", titleSettings);
        titleMap.put("hasAccess", "true");
        titleMap.put("AssociatedWithUOM", "false");
        titleMap.put("name", "Title");
        titleMap.put("DB Unit", "");
        titleMap.put("isMultiVal", "false");
        titleMap.put("suiteDirectory", "documentcentral");
        titleMap.put("suiteKey", "LibraryCentral");
        titleMap.put("label", "\u6807\u9898");
        titleMap.put("expression_businessobject", "attribute[Title].value");
        titleMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        titleMap.putAll(map);
        return titleMap;
    }

    /**
     * 获取创建Library Fields 中的descriptionMap
     *
     * @param
     * @return
     */
    public static Map getLibraryDescriptionMap()
    {
//            {field_display_value=[],
//            settings={Editable=true, Colspan=0, Input Type=textarea, Registered Suite=LibraryCentral, Validate=checkDescriptionLength, Field Type=basic},
//            hasAccess=true, name=Description, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=description, label=描述, StringResourceFileId=emxLibraryCentralStringResource},

        Map descriptionMap = new HashMap();
        descriptionMap.put("field_display_value", new MapList());
        descriptionMap.put("field_value", new MapList());
        Map descriptionSettings = new HashMap();
        descriptionSettings.put("Editable", "true");
        descriptionSettings.put("Colspan", "0");
        descriptionSettings.put("Input Type", "textarea");
        descriptionSettings.put("Registered Suite", "LibraryCentral");
        descriptionSettings.put("Validate", "checkDescriptionLength");
        descriptionSettings.put("Field Type", "basic");
        descriptionMap.put("settings", descriptionSettings);
        descriptionMap.put("hasAccess", "true");
        descriptionMap.put("name", "Description");
        descriptionMap.put("suiteDirectory", "documentcentral");
        descriptionMap.put("suiteKey", "LibraryCentral");
        descriptionMap.put("AssociatedWithUOM", "false");
        descriptionMap.put("expression_businessobject", "description");
        descriptionMap.put("label", "\u63cf\u8ff0");
        descriptionMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return descriptionMap;
    }

    /**
     * 获取创建Library Fields 中的descriptionMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getLibraryDescriptionMap(Map map)
    {
//            {field_display_value=[],
//            settings={Editable=true, Colspan=0, Input Type=textarea, Registered Suite=LibraryCentral, Validate=checkDescriptionLength, Field Type=basic},
//            hasAccess=true, name=Description, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=description, label=描述, StringResourceFileId=emxLibraryCentralStringResource},

        Map descriptionMap = new HashMap();
        descriptionMap.put("field_display_value", new MapList());
        descriptionMap.put("field_value", new MapList());
        Map descriptionSettings = new HashMap();
        descriptionSettings.put("Editable", "true");
        descriptionSettings.put("Colspan", "0");
        descriptionSettings.put("Input Type", "textarea");
        descriptionSettings.put("Registered Suite", "LibraryCentral");
        descriptionSettings.put("Validate", "checkDescriptionLength");
        descriptionSettings.put("Field Type", "basic");
        descriptionMap.put("settings", descriptionSettings);
        descriptionMap.put("hasAccess", "true");
        descriptionMap.put("name", "Description");
        descriptionMap.put("suiteDirectory", "documentcentral");
        descriptionMap.put("suiteKey", "LibraryCentral");
        descriptionMap.put("AssociatedWithUOM", "false");
        descriptionMap.put("expression_businessobject", "description");
        descriptionMap.put("label", "\u63cf\u8ff0");
        descriptionMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        descriptionMap.putAll(map);

        return descriptionMap;
    }


    /**
     * 获取创建library 的 map
     *
     * @param type
     * @param name
     * @param Owner
     * @param description
     * @param Title
     * @return
     */
    public static HashMap getCreateLibraryMap(String type, String name, String Owner, String description, String Title)
    {


        HashMap requestMap = new HashMap();
        requestMap.put("Policy", "Libraries");
        requestMap.put("TypeActual", type);
        requestMap.put("TypeActualOID", null);
        requestMap.put("name", name);
        requestMap.put("Name", name);
        requestMap.put("Revision", "-");
        requestMap.put("timeZone", "-8");
        requestMap.put("timeStamp", String.valueOf(System.currentTimeMillis()));
        requestMap.put("type", type);
        requestMap.put("Owner", Owner);
        requestMap.put("Description", description);
        requestMap.put("mode", "create");
        requestMap.put("Title", Title);

        Locale locale = new Locale("zh_CN");
        requestMap.put("localeObj", locale);
        requestMap.put("autoNameCheck", "false");
        requestMap.put("nameMode", "create");

        MapList fields = getLibraryFields();


        requestMap.put("fields", fields);

        return requestMap;
    }


    /**
     * @param type
     * @param name
     * @param Owner
     * @param description
     * @param Title
     * @return
     */
    public static HashMap getCreateClassMap(String CreateInOID, String CreateIn, String type, String name, String Owner, String description, String Title)
    {


        HashMap requestMap = new HashMap();
        requestMap.put("Policy", "Classification");
        requestMap.put("TypeActual", type);
        requestMap.put("TypeActualOID", null);
        requestMap.put("name", name);
        requestMap.put("Create InOID", CreateInOID);
        requestMap.put("Create In", CreateIn);
        requestMap.put("Name", name);
        requestMap.put("Revision", getClassRevision());
        requestMap.put("timeZone", "-8");
        requestMap.put("timeStamp", String.valueOf(System.currentTimeMillis()));
        requestMap.put("type", type);
        requestMap.put("Owner", Owner);
        requestMap.put("Description", description);
        requestMap.put("mode", "create");
        requestMap.put("Title", Title);

        Locale locale = new Locale("zh_CN");
        requestMap.put("localeObj", locale);
        requestMap.put("autoNameCheck", "false");
        requestMap.put("nameMode", "create");

        MapList fields = getClassFields(Owner);

        requestMap.put("fields", fields);

        return requestMap;
    }


    /**
     * @return
     */
    public static MapList getClassFields(String Owner)
    {

        MapList fields = new MapList();

        Map nameMap = getClassNameMap();

        Map titleMap = getClassTitleMap();

        Map descriptionMap = getClassDescriptionMap();

        Map createdOnMap = getClassCreatedOnMap();

        Map policyMap = getClassPolicyMap();

        Map classOwnerMap = getClassOwnerMap(Owner);


        fields.add(nameMap);
        fields.add(titleMap);
        fields.add(descriptionMap);
        fields.add(createdOnMap);
        fields.add(policyMap);
        fields.add(classOwnerMap);

        return fields;
    }

    /**
     * @param nameMap
     * @param titleMap
     * @param descriptionMap
     * @param createdOnMap
     * @param policyMap
     * @param classOwnerMap
     * @return
     */
    public static MapList getClassFields(Map nameMap, Map titleMap, Map descriptionMap, Map createdOnMap, Map policyMap, Map classOwnerMap)
    {

        MapList fields = new MapList();

        fields.add(nameMap);
        fields.add(titleMap);
        fields.add(descriptionMap);
        fields.add(createdOnMap);
        fields.add(policyMap);
        fields.add(classOwnerMap);

        return fields;
    }

    /**
     * 获取 创建 class nameMap
     *
     * @return
     */
    public static Map getClassNameMap()
    {

//        {field_display_value=[], settings={OnChange Handler=reloadMessageField, Input Type=textbox, Registered Suite=LibraryCentral, Required=true, autoName=自动命名, Validate=validateForBadCharacters, Editable=true, Colspan=0, AutoName Checked=, Field Type=basic, nameMode=autoName}, hasAccess=false, name=Name, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=name, label=名称, StringResourceFileId=emxLibraryCentralStringResource},
        Map nameMap = new HashMap();
        nameMap.put("field_display_value", new MapList());
        nameMap.put("field_value", new MapList());
        Map nameSettings = new HashMap();
        nameSettings.put("OnChange Handler", "reloadMessageField");
        nameSettings.put("Input Type", "textbox");
        nameSettings.put("Registered Suite", "LibraryCentral");
        nameSettings.put("Required", "true");
        nameSettings.put("autoName", "false");
        nameSettings.put("Validate", "validateForBadCharacters");
        nameSettings.put("Editable", "true");
        nameSettings.put("Colspan", "0");
        nameSettings.put("AutoName Checked", "");
        nameSettings.put("Field Type", "basic");
        nameSettings.put("nameMode", "create");
        nameMap.put("settings", nameSettings);
        nameMap.put("hasAccess", "false");
        nameMap.put("name", "Name");
        nameMap.put("suiteDirectory", "documentcentral");
        nameMap.put("suiteKey", "LibraryCentral");
        nameMap.put("expression_businessobject", "name");
        nameMap.put("label", "\u540d\u79f0");
        nameMap.put("StringResourceFileId", "emxLibraryCentralStringResource");
        return nameMap;
    }


    /**
     * 获取 创建 class nameMap
     *
     * @param map 自定义参数
     * @return
     */
    public Map getClassNameMap(Map map)
    {

//        {field_display_value=[], settings={OnChange Handler=reloadMessageField, Input Type=textbox, Registered Suite=LibraryCentral, Required=true, autoName=自动命名, Validate=validateForBadCharacters, Editable=true, Colspan=0, AutoName Checked=, Field Type=basic, nameMode=autoName}, hasAccess=false, name=Name, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=name, label=名称, StringResourceFileId=emxLibraryCentralStringResource},
        Map nameMap = new HashMap();
        nameMap.put("field_display_value", new MapList());
        nameMap.put("field_value", new MapList());
        Map nameSettings = new HashMap();
        nameSettings.put("OnChange Handler", "reloadMessageField");
        nameSettings.put("Input Type", "textbox");
        nameSettings.put("Registered Suite", "LibraryCentral");
        nameSettings.put("Required", "true");
        nameSettings.put("autoName", "false");
        nameSettings.put("Validate", "validateForBadCharacters");
        nameSettings.put("Editable", "true");
        nameSettings.put("Colspan", "0");
        nameSettings.put("AutoName Checked", "");
        nameSettings.put("Field Type", "basic");
        nameSettings.put("nameMode", "create");
        nameMap.put("settings", nameSettings);
        nameMap.put("hasAccess", "false");
        nameMap.put("name", "Name");
        nameMap.put("suiteDirectory", "documentcentral");
        nameMap.put("suiteKey", "LibraryCentral");
        nameMap.put("expression_businessobject", "name");
        nameMap.put("label", "\u540d\u79f0");
        nameMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        nameMap.putAll(map);
        return nameMap;
    }

    /**
     * 获取 创建 class titleMap
     *
     * @return
     */
    public static Map getClassTitleMap()
    {
        //        {settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=attribute_Title, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, Field Type=attribute}, DB UnitList=[], hasAccess=true, AssociatedWithUOM=false, label=标题, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], DB Unit=, name=Title, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=attribute[Title].value, isMultiVal=false},

        Map titleMap = new HashMap();
        titleMap.put("field_display_value", new MapList());
        titleMap.put("field_value", new MapList());
        titleMap.put("DB UnitList", new MapList());
        Map titleSettings = new HashMap();
        titleSettings.put("OnChange Handler", "reloadMessageField");
        titleSettings.put("Input Type", "textbox");
        titleSettings.put("Admin Type", "attribute_Title");
        titleSettings.put("Registered Suite", "LibraryCentral");
        titleSettings.put("Required", "true");
        titleSettings.put("Validate", "validateForBadCharacters");
        titleSettings.put("Editable", "true");
        titleSettings.put("Colspan", "0");
        titleSettings.put("Field Type", "attribute");
        titleMap.put("settings", titleSettings);
        titleMap.put("hasAccess", "true");
        titleMap.put("AssociatedWithUOM", "false");
        titleMap.put("name", "Title");
        titleMap.put("isMultiVal", "false");
        titleMap.put("DB Unit", "");
        titleMap.put("suiteDirectory", "documentcentral");
        titleMap.put("suiteKey", "LibraryCentral");
        titleMap.put("label", "\u6807\u9898");
        titleMap.put("expression_businessobject", "attribute[Title].value");
        titleMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return titleMap;
    }

    /**
     * 获取 创建 class titleMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getClassTitleMap(Map map)
    {
        //        {settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=attribute_Title, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, Field Type=attribute}, DB UnitList=[], hasAccess=true, AssociatedWithUOM=false, label=标题, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], DB Unit=, name=Title, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=attribute[Title].value, isMultiVal=false},

        Map titleMap = new HashMap();
        titleMap.put("field_display_value", new MapList());
        titleMap.put("field_value", new MapList());
        titleMap.put("DB UnitList", new MapList());
        Map titleSettings = new HashMap();
        titleSettings.put("OnChange Handler", "reloadMessageField");
        titleSettings.put("Input Type", "textbox");
        titleSettings.put("Admin Type", "attribute_Title");
        titleSettings.put("Registered Suite", "LibraryCentral");
        titleSettings.put("Required", "true");
        titleSettings.put("Validate", "validateForBadCharacters");
        titleSettings.put("Editable", "true");
        titleSettings.put("Colspan", "0");
        titleSettings.put("Field Type", "attribute");
        titleMap.put("settings", titleSettings);
        titleMap.put("hasAccess", "true");
        titleMap.put("AssociatedWithUOM", "false");
        titleMap.put("name", "Title");
        titleMap.put("isMultiVal", "false");
        titleMap.put("DB Unit", "");
        titleMap.put("suiteDirectory", "documentcentral");
        titleMap.put("suiteKey", "LibraryCentral");
        titleMap.put("label", "\u6807\u9898");
        titleMap.put("expression_businessobject", "attribute[Title].value");
        titleMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return titleMap;
    }


    /**
     * 获取 创建 class descriptionMap
     *
     * @return
     */
    public static Map getClassDescriptionMap()
    {
        //        {field_display_value=[], settings={Editable=true, Colspan=0, Input Type=textarea, Registered Suite=LibraryCentral, Validate=checkDescriptionLength, Field Type=basic}, hasAccess=true, name=Description, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=description, label=描述, StringResourceFileId=emxLibraryCentralStringResource},
        Map descriptionMap = new HashMap();
        descriptionMap.put("field_display_value", new MapList());
        descriptionMap.put("field_value", new MapList());
        Map descriptionSettings = new HashMap();
        descriptionSettings.put("Editable", "true");
        descriptionSettings.put("Colspan", "0");
        descriptionSettings.put("Input Type", "textarea");
        descriptionSettings.put("Registered Suite", "LibraryCentral");
        descriptionSettings.put("Validate", "checkDescriptionLength");
        descriptionSettings.put("Field Type", "basic");
        descriptionMap.put("settings", descriptionSettings);
        descriptionMap.put("hasAccess", "true");
        descriptionMap.put("name", "Description");
        descriptionMap.put("suiteDirectory", "documentcentral");
        descriptionMap.put("suiteKey", "LibraryCentral");
        descriptionMap.put("AssociatedWithUOM", "false");
        descriptionMap.put("expression_businessobject", "description");
        descriptionMap.put("label", "\u63cf\u8ff0");
        descriptionMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return descriptionMap;
    }


    /**
     * 获取 创建 class descriptionMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getClassDescriptionMap(Map map)
    {
        //        {field_display_value=[], settings={Editable=true, Colspan=0, Input Type=textarea, Registered Suite=LibraryCentral, Validate=checkDescriptionLength, Field Type=basic}, hasAccess=true, name=Description, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=description, label=描述, StringResourceFileId=emxLibraryCentralStringResource},
        Map descriptionMap = new HashMap();
        descriptionMap.put("field_display_value", new MapList());
        descriptionMap.put("field_value", new MapList());
        Map descriptionSettings = new HashMap();
        descriptionSettings.put("Editable", "true");
        descriptionSettings.put("Colspan", "0");
        descriptionSettings.put("Input Type", "textarea");
        descriptionSettings.put("Registered Suite", "LibraryCentral");
        descriptionSettings.put("Validate", "checkDescriptionLength");
        descriptionSettings.put("Field Type", "basic");
        descriptionMap.put("settings", descriptionSettings);
        descriptionMap.put("hasAccess", "true");
        descriptionMap.put("name", "Description");
        descriptionMap.put("suiteDirectory", "documentcentral");
        descriptionMap.put("suiteKey", "LibraryCentral");
        descriptionMap.put("AssociatedWithUOM", "false");
        descriptionMap.put("expression_businessobject", "description");
        descriptionMap.put("label", "\u63cf\u8ff0");
        descriptionMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        descriptionMap.putAll(map);
        return descriptionMap;
    }


    /**
     * 获取 创建 class createdOnMap
     *
     * @return
     */
    public static Map getClassCreatedOnMap()
    {
//        {settings={Admin Type=attribute_CreatedOn, Registered Suite=LibraryCentral, Required=false, format=date, Editable=true, Colspan=0, Access Function=isDocumentCentalType, Access Program=emxLibraryCentralCommon, Field Type=attribute, Show Clear Button=true}, DB Unit=, DB UnitList=[], hasAccess=false, name=CreatedOn, AssociatedWithUOM=false, expression_businessobject=attribute[Created On].value, label=emxDocumentCentral.Common.Created_On},
        Map createdOnMap = new HashMap();
        createdOnMap.put("field_display_value", new MapList());
        createdOnMap.put("field_value", new MapList());
        Map createdOnSettings = new HashMap();
        createdOnSettings.put("Admin Type", "attribute_CreatedOn");
        createdOnSettings.put("Registered Suite", "LibraryCentral");
        createdOnSettings.put("Required", "false");
        createdOnSettings.put("format", "date");
        createdOnSettings.put("Editable", "true");
        createdOnSettings.put("Colspan", "0");
        createdOnSettings.put("Access Function", "isDocumentCentalType");
        createdOnSettings.put("Access Program", "emxLibraryCentralCommon");
        createdOnSettings.put("Show Clear Button", "true");
        createdOnSettings.put("Field Type", "attribute");
        createdOnMap.put("settings", createdOnSettings);
        createdOnMap.put("hasAccess", "true");
        createdOnMap.put("name", "Description");
        createdOnMap.put("suiteDirectory", "documentcentral");
        createdOnMap.put("suiteKey", "LibraryCentral");
        createdOnMap.put("AssociatedWithUOM", "false");
        createdOnMap.put("expression_businessobject", "description");
        createdOnMap.put("label", "\u63cf\u8ff0");
        createdOnMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return createdOnMap;
    }


    /**
     * 获取 创建 class createdOnMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getClassCreatedOnMap(Map map)
    {
//        {settings={Admin Type=attribute_CreatedOn, Registered Suite=LibraryCentral, Required=false, format=date, Editable=true, Colspan=0, Access Function=isDocumentCentalType, Access Program=emxLibraryCentralCommon, Field Type=attribute, Show Clear Button=true}, DB Unit=, DB UnitList=[], hasAccess=false, name=CreatedOn, AssociatedWithUOM=false, expression_businessobject=attribute[Created On].value, label=emxDocumentCentral.Common.Created_On},
        Map createdOnMap = new HashMap();
        createdOnMap.put("field_display_value", new MapList());
        createdOnMap.put("field_value", new MapList());
        Map createdOnSettings = new HashMap();
        createdOnSettings.put("Admin Type", "attribute_CreatedOn");
        createdOnSettings.put("Registered Suite", "LibraryCentral");
        createdOnSettings.put("Required", "false");
        createdOnSettings.put("format", "date");
        createdOnSettings.put("Editable", "true");
        createdOnSettings.put("Colspan", "0");
        createdOnSettings.put("Access Function", "isDocumentCentalType");
        createdOnSettings.put("Access Program", "emxLibraryCentralCommon");
        createdOnSettings.put("Show Clear Button", "true");
        createdOnSettings.put("Field Type", "attribute");
        createdOnMap.put("settings", createdOnSettings);
        createdOnMap.put("hasAccess", "true");
        createdOnMap.put("name", "Description");
        createdOnMap.put("suiteDirectory", "documentcentral");
        createdOnMap.put("suiteKey", "LibraryCentral");
        createdOnMap.put("AssociatedWithUOM", "false");
        createdOnMap.put("expression_businessobject", "description");
        createdOnMap.put("label", "\u63cf\u8ff0");
        createdOnMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        createdOnMap.putAll(map);

        return createdOnMap;
    }


    /**
     * 获取 创建 class policyMap
     *
     * @return
     */
    public static Map getClassPolicyMap()
    {
//        {settings={Range Function=getPolicies, Input Type=combobox, OnChange Handler=reloadMessageField, Admin Type=Policy, Registered Suite=LibraryCentral, Range Program=emxLibraryCentralCommon, Editable=true, Colspan=0, Field Type=basic}, hasAccess=true, field_display_choices=[分类], label=策略, field_choices=[Classification], StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], Attribute Sort Type=string, name=Policy, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=policy},
        Map policyMap = new HashMap();
        StringList policy_field_choices = new StringList();
        policy_field_choices.add("Classification");

        StringList policy_field_display_choices = new StringList();
        policy_field_display_choices.add("\u5206\u7c7b");

        policyMap.put("field_display_value", new MapList());
        policyMap.put("field_value", new MapList());
        policyMap.put("field_choices", policy_field_choices);
        policyMap.put("field_display_choices", policy_field_display_choices);
        Map policySettings = new HashMap();
        policySettings.put("Range Function", "getPolicies");
        policySettings.put("Input Type", "combobox");
        policySettings.put("OnChange Handler", "reloadMessageField");
        policySettings.put("Admin Type", "Policy");
        policySettings.put("Registered Suite", "LibraryCentral");
        policySettings.put("Range Program", "emxLibraryCentralCommon");
        policySettings.put("Editable", "true");
        policySettings.put("Required", "false");
        policySettings.put("Colspan", "0");
        policySettings.put("Field Type", "basic");
        policyMap.put("settings", policySettings);
        policyMap.put("hasAccess", "true");
        policyMap.put("name", "Policy");
        policyMap.put("Attribute Sort Type", "string");
        policyMap.put("suiteDirectory", "documentcentral");
        policyMap.put("suiteKey", "LibraryCentral");
        policyMap.put("expression_businessobject", "policy");
        policyMap.put("label", "\u7b56\u7565");
        policyMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return policyMap;

    }


    /**
     * 获取 创建 class policyMap
     *
     * @param map 自定义参数
     * @return
     */
    public static Map getClassPolicyMap(Map map)
    {
//        {settings={Range Function=getPolicies, Input Type=combobox, OnChange Handler=reloadMessageField, Admin Type=Policy, Registered Suite=LibraryCentral, Range Program=emxLibraryCentralCommon, Editable=true, Colspan=0, Field Type=basic}, hasAccess=true, field_display_choices=[分类], label=策略, field_choices=[Classification], StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], Attribute Sort Type=string, name=Policy, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=policy},
        Map policyMap = new HashMap();
        StringList policy_field_choices = new StringList();
        policy_field_choices.add("Classification");

        StringList policy_field_display_choices = new StringList();
        policy_field_display_choices.add("\u5206\u7c7b");

        policyMap.put("field_display_value", new MapList());
        policyMap.put("field_value", new MapList());
        policyMap.put("field_choices", policy_field_choices);
        policyMap.put("field_display_choices", policy_field_display_choices);
        Map policySettings = new HashMap();
        policySettings.put("Range Function", "getPolicies");
        policySettings.put("Input Type", "combobox");
        policySettings.put("OnChange Handler", "reloadMessageField");
        policySettings.put("Admin Type", "Policy");
        policySettings.put("Registered Suite", "LibraryCentral");
        policySettings.put("Range Program", "emxLibraryCentralCommon");
        policySettings.put("Editable", "true");
        policySettings.put("Required", "false");
        policySettings.put("Colspan", "0");
        policySettings.put("Field Type", "basic");
        policyMap.put("settings", policySettings);
        policyMap.put("hasAccess", "true");
        policyMap.put("name", "Policy");
        policyMap.put("Attribute Sort Type", "string");
        policyMap.put("suiteDirectory", "documentcentral");
        policyMap.put("suiteKey", "LibraryCentral");
        policyMap.put("expression_businessobject", "policy");
        policyMap.put("label", "\u7b56\u7565");
        policyMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        policyMap.putAll(map);

        return policyMap;

    }


    /**
     * 获取 创建 class ownerMap
     *
     * @param Owner 所有者
     * @return
     */
    public static Map getClassOwnerMap(String Owner)
    {
        //        {field_popup=true, settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=Owner, Type Ahead Validate=true, TypeAhead Function=getSearchResults, Field Type=basic, Default=2017, Type Ahead Mapping=FIRSTNAME,LASTNAME,NAME, Show Clear Button=true, Allow Manual Edit=true, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, TypeAhead=true, TypeAhead Program=emxTypeAheadFullSearch},
//        hasAccess=true, range=../common/emxFullSearch.jsp?selection=single&field=TYPES=type_Person:CURRENT=policy_Person.state_Active&fieldNameActual=Owner&suiteKey=LibraryCentral&fieldNameOID=OwnerOID&type=PERSON_CHOOSER&showInitialResults=true&fieldNameDisplay=OwnerDisplay&submitURL=../common/AEFSearchUtil.jsp&form=AEFSearchPersonForm&selection=single&table=AEFPersonChooserDetails&, label=所有者, userName=2017, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], name=Owner, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=owner},
        Map ownerMap = new HashMap();

        ownerMap.put("field_display_value", new MapList());
        ownerMap.put("field_value", new MapList());
        Map ownerSettings = new HashMap();
        ownerSettings.put("Input Type", "textbox");
        ownerSettings.put("OnChange Handler", "reloadMessageField");
        ownerSettings.put("Admin Type", "Owner");
        ownerSettings.put("Type Ahead Validate", "true");
        ownerSettings.put("TypeAhead Function", "getSearchResults");
        ownerSettings.put("Field Type", "basic");
        ownerSettings.put("Default", Owner);
        ownerSettings.put("Type Ahead Mapping", "FIRSTNAME,LASTNAME,NAME");
        ownerSettings.put("Show Clear Button", "true");
        ownerSettings.put("Allow Manual Edit", "true");
        ownerSettings.put("Registered Suite", "LibraryCentral");
        ownerSettings.put("Required", "true");
        ownerSettings.put("Editable", "true");
        ownerSettings.put("Colspan", "0");
        ownerSettings.put("TypeAhead", "true");
        ownerSettings.put("TypeAhead Program", "emxTypeAheadFullSearch");
        ownerMap.put("settings", ownerSettings);
        ownerMap.put("hasAccess", "true");
        ownerMap.put("field_popup", "true");
        ownerMap.put("field", "TYPES=type_Person:CURRENT=policy_Person.state_Active");
        ownerMap.put("type", "PERSON_CHOOSER");
        ownerMap.put("name", "Owner");
        ownerMap.put("suiteDirectory", "documentcentral");
        ownerMap.put("suiteKey", "LibraryCentral");
        ownerMap.put("expression_businessobject", "owner");
        ownerMap.put("label", "\u7b56\u7565");
        ownerMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        return ownerMap;
    }


    /**
     * 获取 创建 class ownerMap
     *
     * @param map   自定义参数
     * @param Owner 所有者
     * @return
     */
    public static Map getClassOwnerMap(Map map, String Owner)
    {
        //        {field_popup=true, settings={Input Type=textbox, OnChange Handler=reloadMessageField, Admin Type=Owner, Type Ahead Validate=true, TypeAhead Function=getSearchResults, Field Type=basic, Default=2017, Type Ahead Mapping=FIRSTNAME,LASTNAME,NAME, Show Clear Button=true, Allow Manual Edit=true, Registered Suite=LibraryCentral, Required=true, Editable=true, Colspan=0, TypeAhead=true, TypeAhead Program=emxTypeAheadFullSearch},
//        hasAccess=true, range=../common/emxFullSearch.jsp?selection=single&field=TYPES=type_Person:CURRENT=policy_Person.state_Active&fieldNameActual=Owner&suiteKey=LibraryCentral&fieldNameOID=OwnerOID&type=PERSON_CHOOSER&showInitialResults=true&fieldNameDisplay=OwnerDisplay&submitURL=../common/AEFSearchUtil.jsp&form=AEFSearchPersonForm&selection=single&table=AEFPersonChooserDetails&, label=所有者, userName=2017, StringResourceFileId=emxLibraryCentralStringResource, field_display_value=[], name=Owner, suiteDirectory=documentcentral, field_value=[], suiteKey=LibraryCentral, expression_businessobject=owner},
        Map ownerMap = new HashMap();

        ownerMap.put("field_display_value", new MapList());
        ownerMap.put("field_value", new MapList());
        Map ownerSettings = new HashMap();
        ownerSettings.put("Input Type", "textbox");
        ownerSettings.put("OnChange Handler", "reloadMessageField");
        ownerSettings.put("Admin Type", "Owner");
        ownerSettings.put("Type Ahead Validate", "true");
        ownerSettings.put("TypeAhead Function", "getSearchResults");
        ownerSettings.put("Field Type", "basic");
        ownerSettings.put("Default", Owner);
        ownerSettings.put("Type Ahead Mapping", "FIRSTNAME,LASTNAME,NAME");
        ownerSettings.put("Show Clear Button", "true");
        ownerSettings.put("Allow Manual Edit", "true");
        ownerSettings.put("Registered Suite", "LibraryCentral");
        ownerSettings.put("Required", "true");
        ownerSettings.put("Editable", "true");
        ownerSettings.put("Colspan", "0");
        ownerSettings.put("TypeAhead", "true");
        ownerSettings.put("TypeAhead Program", "emxTypeAheadFullSearch");
        ownerMap.put("settings", ownerSettings);
        ownerMap.put("hasAccess", "true");
        ownerMap.put("field_popup", "true");
        ownerMap.put("field", "TYPES=type_Person:CURRENT=policy_Person.state_Active");
        ownerMap.put("type", "PERSON_CHOOSER");
        ownerMap.put("name", "Owner");
        ownerMap.put("suiteDirectory", "documentcentral");
        ownerMap.put("suiteKey", "LibraryCentral");
        ownerMap.put("expression_businessobject", "owner");
        ownerMap.put("label", "\u7b56\u7565");
        ownerMap.put("StringResourceFileId", "emxLibraryCentralStringResource");

        ownerMap.putAll(map);

        return ownerMap;
    }

    /**
     * @return
     */
    public static String getClassRevision()
    {
        return System.currentTimeMillis() + StringUtil.getRandom(6);
    }


    /**
     * 获取库下面的库分类
     *
     * @param context
     * @param libraryId
     * @return
     */
    public static MapList getClasses(Context context, String libraryId) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, libraryId, Constants.type_GeneralClass, Constants.rel_Subclass, false, true, (short) 0);
        return classObjs;
    }


    /**
     * 获取库下面的库分类
     *
     * @param context
     * @param libraryId
     * @return
     */
    public static MapList getClasses(Context context, String libraryId, short level) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, libraryId, Constants.type_GeneralClass, Constants.rel_Subclass, false, true, level);
        return classObjs;
    }


    /**
     * 获取指定层级库下面的库分类
     *
     * @param context
     * @param libraryId
     * @return
     */
    public static MapList getLevelClasses(Context context, String libraryId, short level) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedLevelObjects(context, libraryId, Constants.type_GeneralClass, Constants.rel_Subclass, false, true, level, null, null);
        return classObjs;
    }


    /**
     * 获取指定层级指定属性库下面的库分类
     *
     * @param context
     * @param libraryId
     * @return
     */
    public static MapList getLevelAttrValueClasses(Context context, String libraryId, short level, String attr, String attrValue) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedLevelAttrValueObjects(context, libraryId, Constants.type_GeneralClass, Constants.rel_Subclass, false, true, level, null, null, attr, attrValue);
        return classObjs;
    }


    /**
     * 获取指定层级指定Title库下面的库分类
     *
     * @param context
     * @param libraryId
     * @return
     */
    public static MapList getLevelTitleClasses(Context context, String libraryId, short level, String title) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedLevelAttrValueObjects(context, libraryId, Constants.type_GeneralClass, Constants.rel_Subclass, false, true, level, null, null, "Title", title);
        return classObjs;
    }


    /**
     * 通过对象查找库分类
     *
     * @param context
     * @param objectId
     * @return
     */
    public static MapList getObjClasses(Context context, String objectId) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, objectId, Constants.type_GeneralClass, Constants.rel_ClassifiedItem, true, false, (short) 1);
        return classObjs;
    }


    /**
     * 通过对象查找库分类
     *
     * @param context
     * @param obj
     * @return
     */
    public static MapList getObjClasses(Context context, DomainObject obj) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, obj, Constants.type_GeneralClass, Constants.rel_ClassifiedItem, true, false, (short) 1);
        return classObjs;
    }


    /**
     * 通过库分类查找相关对象
     *
     * @param context
     * @param classId
     * @return
     */
    public static MapList getClassObjs(Context context, String classId) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, classId, "*", Constants.rel_ClassifiedItem, false, true, (short) 1);
        return classObjs;
    }


    /**
     * 通过库分类查找相关对象
     *
     * @param context
     * @param obj
     * @return
     */
    public static MapList getClassObjs(Context context, DomainObject obj) throws Exception
    {
        MapList classObjs = HDomainObject.getRelatedObjects(context, obj, "*", Constants.rel_ClassifiedItem, false, true, (short) 1);
        return classObjs;
    }


    /**
     * 获取库分类的属性组
     *
     * @param context
     * @param classObj
     * @return
     */
    public static MapList getClassGroup(Context context, DomainObject classObj) throws MatrixException
    {
        //库分类id
        String classId = classObj.getObjectId(context);

        //查询map
        Map classMap = new HashMap();
        classMap.put("objectId", classId);

        String[] classArgs = JPO.packArgs(classMap);

        //查询所有的属性组
        MapList groupList = JPO.invoke(context, "emxMultipleClassificationClassification", null, "getAllAttributeGroups", classArgs, MapList.class);

        return groupList;
    }


    /**
     * 获取库分类的属性组
     *
     * @param context
     * @param classId
     * @return
     */
    public static MapList getClassGroup(Context context, String classId) throws MatrixException
    {
        Map classMap = new HashMap();
        classMap.put("objectId", classId);

        String[] classArgs = JPO.packArgs(classMap);

        //查询所有的属性组
        MapList groupList = JPO.invoke(context, "emxMultipleClassificationClassification", null, "getAllAttributeGroups", classArgs, MapList.class);

        return groupList;
    }


    /**
     * 获取属性组属性
     *
     * @param context
     * @param classId 库分类id
     * @return
     */
    public static MapList getGroupAttrList(Context context, String classId) throws MatrixException
    {

        MapList result = new MapList();


        //查询所有的属性组
        MapList groupList = getClassGroup(context, classId);

        //获取所有属性组的属性

        for (int i = 0; i < groupList.size(); i++)
        {
            Map groupMap = (Map) groupList.get(i);

            String objectId_i = (String) groupMap.get(DomainConstants.SELECT_ID);

            Map programMap = new HashMap();
            programMap.put("objectName", objectId_i);

            String[] attrArgs = JPO.packArgs(programMap);

            //查询属性组下的属性
            MapList groutAttrList = JPO.invoke(context, "emxMultipleClassificationAttributeGroup", null, "getRelatedAttributes", attrArgs, MapList.class);

            result.addAll(groutAttrList);
        }

        return result;
    }


}
